#pragma once

#include <QWidget>
#include <QFile>
#include <QFileInfo>
#include <QThread>
#include "const.h"
#include "httpcommon.h"
#include "ui_uploaditem.h"
#include "pthread.h"
#include "log.h"

class UploadItem : public QWidget
{
    Q_OBJECT

public:
	UploadItem(QString itemID, QString filePath, QString status, QString uploadUrl, int progress, QString dirID, QWidget *parent = Q_NULLPTR);
	~UploadItem();
	static void* processUploadProc(void* args);
	QString status() { return m_status; };
	void upload();
	void cancelUpload();
protected:
	void enterEvent(QEvent *event);
	void leaveEvent(QEvent *event);
	public Q_SLOTS:
	void on_pbDelete_clicked();
	void on_pbPause_clicked();
	void on_pbResume_clicked();
	private Q_SLOTS:
	void refreshProgressbarSlot(int progress);
	void changeStatus(QString status);
Q_SIGNALS:
	void changeStatusSignal(QString);
	void refreshProgressbarSignal(int);
	void updateProgressValueSignal(QString, int);
	void finishUploadSignal(QString, QString, QString, int, QString);
	void pauseUploadSignal(QString);
	void resumeUploadSignal(QString);
	void deleteUploadSignal(QString);
private:
	void startUpload();
	void stopUpload();
private:
    Ui::UploadItem ui;
	QString m_itemID;
	QString m_filePath;
	QString m_status;
	pthread_t m_tidUploadProcess;
	QString m_uploadUrl;
	int m_progress;
	QString m_dirID;
};
